<?php

/**
 * role filter form base class.
 *
 * @package    e-DSL
 * @subpackage filter
 * @author     Your name here
 * @version    SVN: $Id: sfDoctrineFormFilterGeneratedTemplate.php 29570 2010-05-21 14:49:47Z Kris.Wallsmith $
 */
abstract class BaseroleFormFilter extends BaseFormFilterDoctrine
{
  public function setup()
  {
    $this->setWidgets(array(
      'description'        => new sfWidgetFormFilterInput(),
      'titre'              => new sfWidgetFormFilterInput(),
      'modifDemandes'      => new sfWidgetFormChoice(array('choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no'))),
      'technicien'         => new sfWidgetFormChoice(array('choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no'))),
      'interne'            => new sfWidgetFormChoice(array('choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no'))),
      'reaffectation'      => new sfWidgetFormChoice(array('choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no'))),
      'permissions_id'     => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('permissions'), 'add_empty' => true)),
      'activeStatus'       => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'created_at'         => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
      'updated_at'         => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
      'reportdef_list'     => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'reportdef')),
      'filterdef_list'     => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'filterdef')),
      'documentation_list' => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'documentation')),
    ));

    $this->setValidators(array(
      'description'        => new sfValidatorPass(array('required' => false)),
      'titre'              => new sfValidatorPass(array('required' => false)),
      'modifDemandes'      => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))),
      'technicien'         => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))),
      'interne'            => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))),
      'reaffectation'      => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))),
      'permissions_id'     => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('permissions'), 'column' => 'id')),
      'activeStatus'       => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'created_at'         => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
      'updated_at'         => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
      'reportdef_list'     => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'reportdef', 'required' => false)),
      'filterdef_list'     => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'filterdef', 'required' => false)),
      'documentation_list' => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'documentation', 'required' => false)),
    ));

    $this->widgetSchema->setNameFormat('role_filters[%s]');

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

    $this->setupInheritance();

    parent::setup();
  }

  public function addReportdefListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query
      ->leftJoin($query->getRootAlias().'.reportrole reportrole')
      ->andWhereIn('reportrole.reportdef_id', $values)
    ;
  }

  public function addFilterdefListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query
      ->leftJoin($query->getRootAlias().'.filterdef_role_roles_link filterdef_role_roles_link')
      ->andWhereIn('filterdef_role_roles_link.filterdef_id', $values)
    ;
  }

  public function addDocumentationListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query
      ->leftJoin($query->getRootAlias().'.documentationrole documentationrole')
      ->andWhereIn('documentationrole.documentation_id', $values)
    ;
  }

  public function getModelName()
  {
    return 'role';
  }

  public function getFields()
  {
    return array(
      'id'                 => 'Number',
      'description'        => 'Text',
      'titre'              => 'Text',
      'modifDemandes'      => 'Boolean',
      'technicien'         => 'Boolean',
      'interne'            => 'Boolean',
      'reaffectation'      => 'Boolean',
      'permissions_id'     => 'ForeignKey',
      'activeStatus'       => 'Number',
      'created_at'         => 'Date',
      'updated_at'         => 'Date',
      'reportdef_list'     => 'ManyKey',
      'filterdef_list'     => 'ManyKey',
      'documentation_list' => 'ManyKey',
    );
  }
}
